	package pit.com.ordermobilesystem;
		
		
import pit.com.ordermobile.classer.Category;
import pit.com.ordermobile.classer.Description;
import pit.com.ordermobilesystem.OrderMobileProvider.CategoryTable;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.database.Cursor;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
		
		public class MenuOrderMobile  extends Activity {			  
				EditText edt;
				OrderMobileProvider provider;
				@Override
			    public void onCreate(Bundle savedInstanceState) {
			        super.onCreate(savedInstanceState);
			        setContentView(R.layout.main);			        
			        edt = (EditText)this.findViewById(R.id.edt);			        
			        addUser();
			      //  displayAllUsers();
			        this.findViewById(R.id.displayUser).setOnClickListener(btnDisplayClick);			        
			        this.findViewById(R.id.addUser).setOnClickListener(btndeled);
			    }			    
				OnClickListener btndeled = new OnClickListener() {					
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						deled();
					}
				};				
				OnClickListener btnDisplayClick = new OnClickListener() {				
					@Override
					public void onClick(View v) {
						displayAllUsers();
					}
				};			    
				public void deled(){
					/**
					 * vứng đề là chưa sử dụng delete 
					 */
					//String[] araname ={"Mon 1","Mon 2","Mon 3","Mon 4","Mon 5","Mon 6"};
					 getContentResolver().delete(OrderMobileProvider.CATEGORY_CONTENT_URI,null, null);
				}
			    
			    public void addUser() {	
			    	String aray[]={"Mon 1","Mon 2","Mon 3","Mon 4","Mon 5","Mon 6"};
			    	provider = new OrderMobileProvider();
			    	String name;
			    	Category category = new Category();
			    	/**
			    	 * chưa sửa dụng insert của provider 
			    	 * và nếu sử dụng getConte... thì chỉ lưu được 1 dòng
			    	 */
			    for(int i=0;i<aray.length;i++){				    	
			    	name= aray[i];
			    	category.setNameCategory(name);
			    	//provider.insert(provider.CATEGORY_CONTENT_URI, provider.getcontentValuesCategory(category));
			    	Uri uriInsert = getContentResolver().insert(OrderMobileProvider.CATEGORY_CONTENT_URI, OrderMobileProvider.getcontentValuesCategory(category));			    			    	
			    }
			    
			    }
			    public void displayAllUsers(){
			    	StringBuilder sb = new StringBuilder();
			    	Uri uri = OrderMobileProvider.CATEGORY_CONTENT_URI;
			    	Cursor cursor = managedQuery(uri, null, null, null, null);			    	
			    	if(cursor.moveToFirst()){
			    		do{
			    			String userRecord = "ID = " + cursor.getString(cursor.getColumnIndex(CategoryTable.ID_CATEGORY)) 
			    					+ " Name = "+cursor.getString(cursor.getColumnIndex(CategoryTable.NAME_CATEGORY)) ;
			    			sb.append(userRecord);
			    			sb.append("\n");
			    		}while(cursor.moveToNext());
			    	}
			    	else
			    	{
			    		sb.append("Chua co du lieu");
			    	}
			    	
			    	((TextView)this.findViewById(R.id.userList)).setText(sb.toString());
			    }
			}